package se.liu.oschi129.timer;

/**
 * This is a timer class. The class uses discrete time steps and can only be ticked by using the method TimerTick().
 * 
 * @author oschi129
 */
public class Timer {

	// The cooldown of the timer
	private int cooldown;
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public Timer(int cooldown) {
		this.cooldown = cooldown;
	}
	
	public Timer() {
		this(0);
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	/** Sets the timers cooldown to a new value (cooldown > 0) */
	public void set(int cooldown) {
		if (cooldown > 0)
		this.cooldown = cooldown;
	}
	
	/** Returns the number of ticks left until the timer is cool */
	public int cooldown() {
		return cooldown;
	}
	
	/** Ticks the timer one time decreasing the cooldown by 1 */
	public void tick() {
		if (cooldown > 0)
			cooldown--;
	}
	
	/** Returns true if the timer is cool */
	public boolean cool() {
		return (cooldown == 0);
	}
	
}
